<template>
  <Model
    :title="row.edit ? '编辑' : '添加'"
    :width="800"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form"
      ><FormDoubleItem :labels="['名字', '教师工号']">
        <a-input
          slot="left"
          v-model="row.name"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          v-model="row.teacherId"
          placeholder="请输入内容"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['授权号', '获批时间']">
        <a-input
          slot="left"
          v-model="row.number"
          placeholder="请输入内容"
        ></a-input>
        <a-date-picker
          key="1"
          slot="right"
          v-if="!!row.time"
          show-time
          :defaultValue="moment(row.time, 'YYYY-MM-DD HH:mm:ss')"
          format="YYYY-MM-DD HH:mm:ss"
          @change="onChange"
        />
        <a-date-picker
          key="2"
          slot="right"
          v-if="!row.time"
          show-time
          format="YYYY-MM-DD HH:mm:ss"
          @change="onChange"
        />
      </FormDoubleItem>
      <FormDoubleItem :labels="['审核', '类型']">
        <a-select
          slot="left"
          show-search
          :default-value="row.check"
          placeholder="请选择"
          :disabled="row.edit"
          option-filter-prop="children"
          style="width: 100%"
          @change="(e) => changeValue(e, 'check')"
        >
          <a-select-option v-for="item in check" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
        <a-select
          slot="right"
          show-search
          :default-value="row.type"
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          @change="(e) => changeValue(e, 'type')"
        >
          <a-select-option v-for="item in patentType" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['是否应用', '联合专利']">
        <a-radio-group
          slot="left"
          name="application"
          :default-value="row.application"
          @change="(e) => changeValue(e.target.value, 'application')"
        >
          <a-radio :value="0"> 否 </a-radio>
          <a-radio :value="1"> 是 </a-radio>
        </a-radio-group>
        <a-radio-group
          slot="right"
          name="application"
          :default-value="row.success"
          @change="(e) => changeValue(e.target.value, 'success')"
        >
          <a-radio :value="0"> 否 </a-radio>
          <a-radio :value="1"> 是 </a-radio>
        </a-radio-group>
      </FormDoubleItem>
    </Form>
  </Model>
</template>

<script>
import Model from "components/common/model/Model";
import Form from "components/common/form/Form";
import FormItem from "components/common/form/formItem/FormItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";
import { check, patentType } from "assets/data/other";
import { hasPropertyEmpty } from "common/index";
import moment from "moment";
export default {
  components: {
    Model,
    Form,
    FormDoubleItem,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      check,
      patentType,
      tao: 1,
      moment,
    };
  },
  methods: {
    onChange(value, dateString) {
      this.row.time = dateString;
    },
    changeValue(value, key) {
      this.row[key] = value;
    },
    confirm() {
      const row = this.row;
      row.type = patentType.indexOf(row.type);
      row.check = check.indexOf(row.check);

      this.$emit("confirm", {
        ...row,
      });
    },
    cancel() {
      this.$emit("cancel");
    },
  },
};
</script>

<style lang="less" scoped>
.t-form {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-items: center;
  padding-right: 30px;
  .ant-btn {
    width: 150px !important;
  }
}
</style>